﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.Admin
{
    public partial class WebForm25 : System.Web.UI.Page
    {
        private DataClassesHeaxlthDataContext dc = new DataClassesHeaxlthDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            string password = mahoa_giaima.maHoa(this.TextBoxNewPassword.Text);
            changepassword(password);
        }
        public void changepassword(string password)
        {
            AdminLogin ad = (AdminLogin)Session["admin"];
            AdminLogin admin = this.dc.AdminLogins.Single(h => h.username.Equals(ad.username));
            string pass = mahoa_giaima.giaiMa(admin.password);
            if (this.TextBoxPasswordCurrent.Text == pass)
            {
                if (this.TextBoxNewPassword.Text == this.TextBoxPasswordConfirm.Text)
                {
                    admin.password = password;
                    dc.SubmitChanges();
                    this.LabelKQ3.Text = "Change Password successful";
                    LabelKQ1.Visible = false;
                    LabelKQ2.Visible = false;
                    LabelKQ3.Visible = true;
                }
                else
                {
                    this.LabelKQ2.Text = "Incorrect password confirmation";
                    LabelKQ3.Visible = false;
                    LabelKQ1.Visible = false;
                    LabelKQ2.Visible = true;

                }
            }
            else
            {
                this.LabelKQ1.Text = "Password not correct";
                LabelKQ3.Visible = false;
                LabelKQ2.Visible = false;
                LabelKQ1.Visible = true;
            }
        }
    }
}